home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14299 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  58 lines

  1. Newsgroups: comp.lang.ada,comp.lang.c++
  2. Path: in2.uu.net!world!bobduff
  3. From: bobduff@world.std.com (Robert A Duff)
  4. Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
  5. Message-ID: <Dp1sMM.23q@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. References: <wnewmanDoxrCp.DKv@netcom.com> <leschkes.828053356@ferret>
  8. Date: Fri, 29 Mar 1996 21:20:46 GMT
  9.  
  10. In article <leschkes.828053356@ferret>,
  11. Scott Leschke <leschkes@ferret.cig.mot.com> wrote:
  12. >My first question would be, why do you want redundant instantiations.
  13.  
  14. Usually you don't.  But you might declare a type Apple_Count, and not
  15. know whether anybody wants to do I/O on it.  Then one client does, and
  16. instantiates Text_IO.Integer_IO on Apple_Count.  And another client
  17. independently does the same.  One might like to share the code of the
  18. two instantiations.
  19.  
  20. But, as Bill Newman pointed out, the more important thing is when you
  21. have Apple_Count and Orange_Count, which are logically distinct, but
  22. happen to share the same hardware representation.  That's a more
  23. important case where you'd like shared generic code.
  24.  
  25. Shared generic code isn't easy to implement in general, but many Ada 83
  26. compilers support it, at least for some kinds of generics.  The problem
  27. is that you can't count on it in portable code, so you have to do it "by
  28. hand".  That's not so awful, I suppose -- at least the ugly parts are
  29. buried in one place.
  30.  
  31. >You can use a block statement.  This is different than C++ in the sense
  32. >that objects declared within the block are only in existence within the
  33. >block and are finalized at the end.
  34.  
  35. No, I think this is exactly the same in C++ and Ada.  See r.6.7 of The
  36. C++ Programming Language, Second Edition, by Bjarne Stroustrup.  That
  37. is, if you declare an object in C++ in a local sequence of statements,
  38. it will be finalized at the end of that sequence.  The only difference
  39. is that Ada requires some extra syntactic baggage.
  40.  
  41. >declare
  42. >   Obj : Pkg.SomeType;
  43. >begin
  44. >   Pkg.Operation (Object => Obj);
  45. >   -- Other stuff
  46. >exception
  47. >   when Pkg.Some_Exception =>
  48. >
  49. >      Do_Something;
  50. >end;
  51.  
  52. The exception handler makes this look reasonable, but in the usual case,
  53. where there's no need for any exception handling, and you just want to
  54. declare Obj, the extra 3 lines of code ("declare", "begin", "end") are
  55. just an annoyance.
  56.  
  57. - Bob
  58.